package com.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.bean.ProductBean;
import com.project.service.IProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("product")
@Api(tags = "库存商品控制器")
public class ProductController {
    @Autowired
    private IProductService service;

    @RequiresPermissions("product:*")
    @RequestMapping("cutByItem")
    @ApiOperation(value = "库存商品分页", notes = "库存商品分页")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "pageNO", value = "页码",required = true),
            @ApiImplicitParam(name = "pName", value = "商品名称"),
            @ApiImplicitParam(name = "startNum", value = "库存起始数量"),
            @ApiImplicitParam(name = "endNum", value = "库存结束数量"),
            @ApiImplicitParam(name = "sellPrice", value = "销售价"),
            @ApiImplicitParam(name = "type", value = "类型")
    })
    public IPage<ProductBean> cutByItem(Integer pageNO, String pName, Integer startNum, Integer endNum, Integer sellPrice, String type) {
        return service.cutByItem(pageNO, pName, startNum, endNum, sellPrice, type);
    }

    @RequiresPermissions("product:*")
    @RequestMapping("findByProductId")
    @ApiOperation(value = "查看商品", notes = "查看商品")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "productId", value = "商品id")
    })
    public ProductBean findByProductId(String productId) {
        return service.findByProductId(productId);
    }

    @RequiresPermissions("product:*")
    @RequestMapping("updateSellPrice")
    @ApiOperation(value = "改变销售价", notes = "改变销售价")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "productId", value = "商品id"),
            @ApiImplicitParam(name = "newSellPrice", value = "改变销售价")
    })
    public String updateSellPrice(String productId, Integer newSellPrice) {
        service.updateSellPrice(productId, newSellPrice);
        return "ok";
    }

    @RequiresPermissions("product:*")
    @RequestMapping("cutItem")
    @ApiOperation(value = "按商品名和类型查看库存商品分页", notes = "按商品名和类型查看库存商品分页")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "pageNO", value = "页码",required = true),
            @ApiImplicitParam(name = "pName", value = "商品名称"),
            @ApiImplicitParam(name = "type", value = "类型")
    })
    public IPage<ProductBean> cutItem(Integer pageNO, String pName, String type) {
        return service.cutItem(pageNO, pName, type);
    }
}
